﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseComponent;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using DatabaseComponent;


public partial class HomeEN : System.Web.UI.Page
{

    public Persons mobjUser
    {
        get
        {
            if (ViewState["mobjUser"] == null)
                ViewState["mobjUser"] = System.Guid.NewGuid().ToString();
            return Session[ViewState["mobjUser"].ToString()] as Persons;
        }
        set
        {
            if (ViewState["mobjUser"] == null)
                ViewState["mobjUser"] = System.Guid.NewGuid().ToString();
            Session[ViewState["mobjUser"].ToString()] = value;
        }
    }




    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            checkAndCustomizeSecurity();

            bindFaq();
        }
    }


    /// <summary>
    /// this function will bind the faq for first time
    /// </summary>
    protected void bindFaq()
    {
        FaqsDB objFaqsDB = new FaqsDB(ConnectionStrings.LMS);
        List<Faqs> lstRet = new List<Faqs>();
        List<Faqs> lstNew = objFaqsDB.Select("  ", " order by [FaqQuestionEN] ASC ");

        grdFaq.DataSource = lstNew;
        grdFaq.DataBind();


        
    }

    protected void grdFaq_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        FaqsDB objFaqsDB = new FaqsDB(ConnectionStrings.LMS);
        List<Faqs> lstRet = new List<Faqs>();
        List<Faqs> lstNew = objFaqsDB.Select("  ", " order by [FaqQuestionEN] ASC ");

        grdFaq.DataSource = lstNew;
        grdFaq.PageIndex = e.NewPageIndex;
        grdFaq.DataBind();
    }

    protected void fcSelectFolder_SelectedItemChanged(object sender, CustomEventArgs e)
    {

        Folders objFold = (Folders)e.objArgs;

        if (objFold.lstCourses.Count > 0)
        {
            Response.Redirect("CatalogPageEN.aspx?FolderID=" + objFold.ID);
        }

    }


    /// <summary>
    /// this function will check the security and customize page
    /// </summary>
    private void checkAndCustomizeSecurity()
    {
        mobjUser = GlobalVars.getCurrentPerson();

        if (!mobjUser.lstAllRulesIDs.Contains((long)RulesEnum.Home_page_view))
        {
            Response.Redirect("LoginEN.aspx");

        }



    }


    protected void odsAbout_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {

        AboutUSDB objAboutUSDB = new AboutUSDB(ConnectionStrings.LMS);
        e.ObjectInstance = objAboutUSDB;
    }
    protected void odsCourses_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        CoursesDB objCoursesDB = new DatabaseComponent.CoursesDB(ConnectionStrings.LMS);
        e.ObjectInstance = objCoursesDB;
    }
    protected void odsNews_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        HintsDB objHintsDB = new DatabaseComponent.HintsDB(ConnectionStrings.LMS);
        e.ObjectInstance = objHintsDB;
    }
   


    protected void rptCourses_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        long courseID = 0;
        try
        {
            courseID = ((Courses)e.Item.DataItem).ID;
        }
        catch
        {
            return;
        }
        Courses objCourses = new DatabaseComponent.Courses();


        List<Courses> lstCourses = (new CoursesDB(ConnectionStrings.LMS)).getCoursesByID(courseID);
        if (lstCourses.Count == 0)
            return;

        objCourses = lstCourses[0];

        HyperLink hlEnroll = (HyperLink)e.Item.FindControl("hlEnroll");
        HyperLink lblEnrolled = (HyperLink)e.Item.FindControl("lblEnrolled");

        if (mobjUser.lstCourses.Contains(objCourses))
        {
            hlEnroll.Visible = false;
            lblEnrolled.Visible = true;



            lblEnrolled.NavigateUrl = "start_learn_frame.aspx?id=" + courseID.ToString();
            lblEnrolled.Target = "_blank";


        }
        else
        {
            hlEnroll.Visible = true;
            lblEnrolled.Visible = false;
        }







    }


}
